# Define the remote folder and user/host as variables
REMOTE_FOLDER := "/home/pascal/dvp/_Bundle/_Pyodide/pyodide"
REMOTE_USER_HOST := "pascal@192.168.1.50"
FIATLIGHT_FOLDER := "../../../fiatlight"
PROBABL_FOLDER := "../../../fiatlight/_drafts/_probabl_drafts"

BASE_PACKAGE_LIST := "numpy Pillow pandas ipython requests opencv-python typing-extensions pydantic munch matplotlib future scikit-learn"


default:
  just --list


fiatlight_wheel:
    cd {{FIATLIGHT_FOLDER}} && pipx run build

scatter_wheel:
    cd {{PROBABL_FOLDER}}/scatter && pipx run build


# Copy the dist folder from the remote machine
copy_dist: fiatlight_wheel scatter_wheel
    mkdir -p pyodide_dist
    rsync -avz --delete {{REMOTE_USER_HOST}}:{{REMOTE_FOLDER}}/dist/ pyodide_dist/
    cp {{FIATLIGHT_FOLDER}}/dist/*.whl pyodide_dist/
    cp {{PROBABL_FOLDER}}/scatter/dist/*.whl pyodide_dist/


build_base_packages:
    echo "Building on remote machine"
    echo "==================================="
    echo ""
    ssh {{REMOTE_USER_HOST}} \
    " \
    source ~/miniforge3/etc/profile.d/conda.sh && \
    cd {{REMOTE_FOLDER}} && \
    conda activate pyodide-env && \
    make && \
    pyodide build-recipes {{BASE_PACKAGE_LIST}} \
    "


# Build imgui_bundle pyodide package on a distant computer
build_dist:
    echo "Building on remote machine"
    echo "==================================="
    echo ""
    ssh {{REMOTE_USER_HOST}} \
    " \
    source ~/miniforge3/etc/profile.d/conda.sh && \
    cd {{REMOTE_FOLDER}} && \
    conda activate pyodide-env && \
    pyodide build-recipes imgui_bundle {{BASE_PACKAGE_LIST}} --install \
    "

# Build and copy the dist folder from the remote machine
build_and_copy_dist: build_dist copy_dist


# Run the a webserver on port 8005
srv:
    # python3 -m http.server 8005
    python3 ../../ci_scripts/webserver_multithread_policy.py -p 8005

rsync_tq:
    rsync -avz --delete . pascal@traineq.org:HTML/probabl/

gpt_files_content:
    for f in $(cat f.txt); do echo "===========================================================================";echo "File $f"; echo "==========================================================================="; echo '```'; cat $f; echo '```'; done

# Run a git server for imgui_bundle
git_server_bundle:
    # (to use on another pc:
    #     git remote add mac git://192.168.1.22/imgui_bundle)
    git daemon --reuseaddr --base-path=$(pwd)/../../.. --export-all --verbose --enable=receive-pack
